package filter;

import javax.servlet.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebFilter("/*")
public class CharsetFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {

        /**
         * 1.实现Filter接口，类具有过滤功能
         * 2.配置拦截的url地址
         * 3.dofilter方法中写具体拦截以后的操作
         */
        System.out.println("过滤器开始设置");
        //请求对象预处理设置请求对象的编码
        //响应结果的编码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //继续后续过滤器或servlet的执行
        chain.doFilter(request, response);

    }
}
